(define-module (utils random-utils))

(use-modules (srfi srfi-27))

(define-public make-random-integer-generator
  (lambda* (#:key seed)
    "Get a procedure for generating random integers from 0 up to a not included
bound, which is seeded by the keyword argument seed, which must be a positive
integer."
    (cond
     [seed
      (let ([rand-src (make-random-source)])
        (random-source-pseudo-randomize! rand-src 0 seed)
        (random-source-make-integers rand-src))]
     [else
      (let ([rand-src (make-random-source)])
        ;; Try to make the random source truly random. How this works depends on
        ;; the specific implementation of SRFI-27.
        (random-source-randomize! rand-src)
        (random-source-make-integers rand-src))])))
